package com.young.monitor;

import com.young.monitor.service.FileWatcherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.io.IOException;

@SpringBootApplication
public class SystemMonitorApplication implements CommandLineRunner {

    @Autowired
    private FileWatcherService fileWatcherService;

    public static void main(String[] args) {
        SpringApplication.run(SystemMonitorApplication.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
        new Thread(() -> {
            try {
                fileWatcherService.startWatching();
            } catch (IOException | InterruptedException e) {
                e.printStackTrace();
            }
        }).start();
    }
}
